IF EXISTS (SELECT * FROM sysobjects WHERE type = 'U' AND name = 'DOC2MODULE')
BEGIN
    DROP TABLE [dbo].[DOC2MODULE]
END

GO

CREATE TABLE [dbo].[DOC2MODULE] ( 
	[ID]			INT IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
	[DOC_ID]        INT         NOT NULL,
    [MODULE_ID]     INT         NOT NULL

    CONSTRAINT [PK_DOC2MODULE_ID] PRIMARY KEY CLUSTERED ( 
        [ID] 
    ) ON [PRIMARY],
    
    CONSTRAINT [FK_DOC2MODULE_DOC_ID] FOREIGN KEY ( 
        [DOC_ID]
    ) REFERENCES [dbo].[MODULE_DOC] (
        [ID]
    ),
    
    CONSTRAINT [FK_DOC2MODULE_MODULE_ID] FOREIGN KEY ( 
        [MODULE_ID]
    ) REFERENCES [dbo].[EDUCATION_MODULE] (
        [ID]
    )
    
) ON [PRIMARY] 

CREATE INDEX [IDX_DOC2MODULE_DOC_ID_MODULE_ID] on [dbo].[DOC2MODULE] ([DOC_ID],[MODULE_ID]) 

GO